<template>
  <div class="deep-seek">
    DEEPSEEK对话
    <input
      type="textarea"
      v-model="content"
      placeholder="请输入内容"
      :rows="5"
    ></input>
    <button type="primary" class="mar-top-20" @click="sendBtn"
      >发送</button
    >
  </div>
</template>
<script setup>
import { ref } from "vue";
import axios from "axios";
const content = ref("");
const callDeepSeekAPI =async  (data) => {
  const apiKey = "sk-7d053ff6301e4c84b2f1b2a0779b2784";
  const apiUrl = "https://api.deepseek.com";
  try {
    const response =await axios.post(apiUrl, data, {
      headers: {
        Authorization: `Bearer ${apiKey}`,
        "Content-Type": "application/json",
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
      },
    });
    return response.data;
  } catch (error) {
    console.error("Error calling DeepSeek API:", error);
    throw error;
  }
};
const sendBtn = () => {
  console.log(content.value);
  const data = {
    messages: [{ role: "system", content: content.value }],
    model: "deepseek-chat",
  };
  callDeepSeekAPI(data)
    .then((response) => {
      console.log(response);
    })
    .catch((error) => {
      console.error(error);
    });
};
</script>
